package com.itheima.homework.homework03;

public class SellTickets implements Runnable {
    private int filmTickets = 100;
    private Object object = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (object) {
                if (filmTickets <= 0) {
                    System.out.println(Thread.currentThread().getName() + "电影票卖完啦!!!");
                    break;
                } else {
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "正在售票,还剩余" + (filmTickets - 1) + "张电影票");
                    filmTickets--;
                }
            }
        }
    }
}
